﻿// See https://aka.ms/new-console-template for more information

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Information)
    .WriteTo.Console()
    .WriteTo.File("Logs/log-.txt", rollingInterval: RollingInterval.Day)//表示自动按天创建日志文件，自动把日期拼装到文件名中
    //.WriteTo.Async(x => x.File("Logs/log-.txt"))
    .CreateLogger();

var servicesProvider = new ServiceCollection()
    .AddLogging(buider =>
    {
        buider.AddSerilog();
    }).BuildServiceProvider();


var logger = servicesProvider.GetRequiredService<ILogger<Program>>();

var leveles = (LogLevel[])Enum.GetValues(typeof(LogLevel));

var eventId = 1;
foreach (var levele in leveles)
{
    logger.Log(levele, eventId++, $"这是一条{levele}消息");
}

Console.WriteLine("Hello, World!");
